package engine.newUi
{
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.flag.ResourcesPath;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	
	import flash.events.MouseEvent;
	
	import newx.com.control.NxClip;

	public class CampChooseLogic
	{
		private static var _self:CampChooseLogic;
		
		private var _myDis:CampChooseUI
		
		private var _leftPic:NxClip;
		private var _rightPic:NxClip;
		private var _line:NxClip;
		private var _model:ModelLocator;
		public function CampChooseLogic()
		{
			_model	=	ModelLocator.getInstance();
			_myDis	=	CampChooseUI.getInstance();
			_leftPic				=	_myDis.pic_0;
			_rightPic				=	_myDis.pic_1;
			_line					=	_myDis.line;
			_line.mouseEnabled		=	_line.mouseChildren	=	false;
			_line.visible			=	false;
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_OPEN_CAMP_UI),openUI);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_CHOOSE_CAMP),hideUI);
		}
		
		public static function getInstance():CampChooseLogic
		{
			if(_self == null)
			{
				_self	=	new CampChooseLogic();
			}
			return _self;
		}
		public function addListener():void
		{
			_leftPic.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandle);
			_leftPic.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandle)
			_leftPic.addEventListener(MouseEvent.CLICK, clickHandle);
			
			_rightPic.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandle);
			_rightPic.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandle)
			_rightPic.addEventListener(MouseEvent.CLICK, clickHandle);
		}
		public function removeListener():void
		{
			_leftPic.removeEventListener(MouseEvent.MOUSE_OVER,mouseOverHandle);
			_leftPic.removeEventListener(MouseEvent.MOUSE_OUT,mouseOutHandle)
			_leftPic.removeEventListener(MouseEvent.CLICK, clickHandle);
			
			_rightPic.removeEventListener(MouseEvent.MOUSE_OVER,mouseOverHandle);
			_rightPic.removeEventListener(MouseEvent.MOUSE_OUT,mouseOutHandle)
			_rightPic.removeEventListener(MouseEvent.CLICK, clickHandle);
		}
		private function openUI(e:CustomMsgEvent):void
		{
			_myDis.show();
		}
		private function hideUI(e:CustomMsgEvent):void
		{
			_myDis.hide();
		}
		private function mouseOverHandle(e:MouseEvent):void
		{
			var item:NxClip	=	e.currentTarget as NxClip;
			_line.x		=	item.x;
			_line.y		=	item.y;
			_line.visible	=	true;
			
		}
		private function mouseOutHandle(e:MouseEvent):void
		{
			_line.visible	=	false;
		}
		private function clickHandle(e:MouseEvent):void
		{
			var item:NxClip	=	e.currentTarget as NxClip;
			var chooseIndex:int = 0;
			switch(item)
			{
				case _leftPic:
					chooseIndex	=	1;
					break;
				case _rightPic:
					chooseIndex	=	2;
					break;
			}
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CHOOSE_CAMP,chooseIndex);
		}
	}
}